//
//  LGMineViewController.m
//  ligenyun
//
//  Created by Mac on 2018/3/16.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "LGAccountMangeViewController.h"
#import "LGRechargeViewController.h"
#import "TGPointChangeViewController.h"
#import "LGPointHistoryViewController.h"
#import "LGCoinHitsoryViewController.h";
@interface LGAccountMangeViewController ()
@property(nonatomic, strong) NSArray                     *dataSouce;
@end

@implementation LGAccountMangeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"账户管理";
    
    [self configSubViewWithUserModel:nil];
    [self configDataSouce];
    // Do any additional setup after loading the view.
}

#pragma mark --subView
- (void)configSubViewWithUserModel:(LGUserModel*)userModel{
    UIView * header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 120)];
    header.backgroundColor = [UIColor whiteColor];
    
    STButton * imageButton = [[STButton alloc] initWithFrame:CGRectMake(20, 20, 49, 44)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:[UIImage imageNamed:@"添加股东账户"]
                                                     image:nil];
    imageButton.centerX = header.width / 2;
    imageButton.userInteractionEnabled = NO;
    imageButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    [header addSubview:imageButton];
    
    STLabel * titleLable = [[STLabel alloc] initWithFrame:CGRectMake(0, imageButton.bottom + 10, UIScreenWidth, 20)
                                                     text:@"账户余额:3000礼根币"
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:titleLable];
    
    STLabel * moneyLable = [[STLabel alloc] initWithFrame:CGRectMake(0, titleLable.bottom + 5, UIScreenWidth, 20)
                                                     text:@"账号积分:3000币"
                                                textColor:FirstTextColor
                                                     font:15
                                              isSizetoFit:NO
                                            textAlignment:NSTextAlignmentCenter];
    [header addSubview:moneyLable];
    
    self.tableView.tableHeaderView = header;
    
}
- (void)configDataSouce{
    
    NSArray * sectionOne = @[[[STTableEasyModel alloc] initWithTextString:@"礼根币充值" imageName:@"充值2"]];
    
    NSArray * sectionTwo = @[
                             [[STTableEasyModel alloc] initWithTextString:@"积分兑换" imageName:@"积分"],
                             [[STTableEasyModel alloc] initWithTextString:@"礼根币日志" imageName:@"操作日志"],
                             [[STTableEasyModel alloc] initWithTextString:@"积分日志" imageName:@"日志"]
                             ];
   
    self.dataSouce = @[sectionOne,sectionTwo];
    [self.tableView reloadData];
}
#pragma --mark UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataSouce.count ;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [self.dataSouce[section] count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 49;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}
- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return [UIView new];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * reuseIdentifier =  @"cell";
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
    }
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    [cell setSt_tableEasyModel:model];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}
#pragma --mark UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    STTableEasyModel * model = self.dataSouce[indexPath.section][indexPath.row];
    if ([model.textString isEqualToString:@"礼根币充值"]) {
        [self onSelctedRechargeCell];
    }
    if ([model.textString isEqualToString:@"积分兑换"]) {
        [self onSelctedPointChageCell];
    }
    if ([model.textString isEqualToString:@"礼根币日志"]) {
        [self onSelctedRechageHistoryCell];
    }
    if ([model.textString isEqualToString:@"积分日志"]) {
        [self onSelctedPointHistoryCell];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark --Action Method
- (void)onSelctedRechargeCell{
    [self.navigationController pushViewController:[LGRechargeViewController new] animated:YES];
}
- (void)onSelctedPointChageCell{
    [self.navigationController pushViewController:[TGPointChangeViewController new] animated:YES];
    
}
- (void)onSelctedRechageHistoryCell{
    [self.navigationController pushViewController:[LGCoinHitsoryViewController new] animated:YES];
    
}
- (void)onSelctedPointHistoryCell{
      [self.navigationController pushViewController:[LGPointHistoryViewController new] animated:YES];
}
@end

